<?php

namespace app\index\model;

use think\Db;
use think\Model;

class BUser extends Model
{
    // 表名
    protected $name = 'b_user';





    public function dian(){


        return $this->hasOne('Qiu','user_id');
    }



    public function dan(){



return Buser::with('dian')->where(true)->select();

    }

    public  function yon()
    {
        Db::startTrans();
        try {


            $this->allowField(true)->save([
                'name' => 'guiqi',
                'age' => 21,



            ]);

            $this->dian()->save([

                'qiuname' => '三国演义',
                'jiage' => 33,
            ]);
            // 提交事务
            print_r('成功了');
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            print_r('失败了');
            Db::rollback();
        }
    }

}
